﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PowerTriggers.ServiceReference;
using System.Management;

namespace PowerTriggers
{
    internal partial class SelectTimePeriod : Form
    {
        private SelectTimePeriod()
        {
            InitializeComponent();
        }

        public SelectTimePeriod(int? milliseconds)
            : this()
        {
            textBox1.Text = milliseconds.HasValue ? milliseconds.Value.ToString() : string.Empty;
        }

        internal int Milliseconds
        {
            get
            {
                return int.Parse(textBox1.Text.Trim());
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                int milliseconds;
                if (!int.TryParse(textBox1.Text.Trim(), out milliseconds) || milliseconds <= 0)
                {
                    MessageBox.Show(this, "Please enter a value for milliseconds greater than zero", "Power Triggers", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (textBox1.CanFocus)
                    {
                        textBox1.Focus();
                    }
                }
                else
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(this, "Error: " + ex.Message, "Power Triggers", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
